package com.glm.fruit;

import com.glm.fruit.entity.CartItem;
import com.glm.fruit.entity.Fruit;
import com.glm.fruit.service.FullReductionPromotion;
import com.glm.fruit.service.ShoppingCart;
import com.glm.fruit.service.StrawberryDiscountPromotion;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Fruit apple = new Fruit("苹果", 8);
        Fruit strawberry = new Fruit("草莓", 13);
        Fruit mango = new Fruit("芒果", 20);

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请选择顾客类型：");
            System.out.println("1. 顾客A（苹果、草莓，无优惠）");
            System.out.println("2. 顾客B（苹果、草莓、芒果，无优惠）");
            System.out.println("3. 顾客C（苹果、草莓、芒果，草莓8折）");
            System.out.println("4. 顾客D（苹果、草莓、芒果，草莓8折+满100减10）");
            System.out.print("请输入选项（1-4）：");
            int option = scanner.nextInt();

            ShoppingCart cart = new ShoppingCart();

            System.out.print("请输入苹果购买斤数：");
            int appleWeight = scanner.nextInt();
            if (appleWeight > 0) cart.addItem(new CartItem(apple, appleWeight));

            System.out.print("请输入草莓购买斤数：");
            int strawberryWeight = scanner.nextInt();
            if (strawberryWeight > 0) cart.addItem(new CartItem(strawberry, strawberryWeight));

            if (option > 1) {
                System.out.print("请输入芒果购买斤数：");
                int mangoWeight = scanner.nextInt();
                if (mangoWeight > 0) cart.addItem(new CartItem(mango, mangoWeight));
            }

            if (option == 3 || option == 4) {
                cart.addPromotion(new StrawberryDiscountPromotion());
            }
            if (option == 4) {
                cart.addPromotion(new FullReductionPromotion());
            }

            System.out.println("总价为: " + cart.calculateTotal() + " 元");
            System.out.print("是否继续购物？(y/n)：");
            String again = scanner.next();
            if (!again.equalsIgnoreCase("y")) {
                break;
            }
        }
        scanner.close();
    }
}
